package com.wolf.controller;
import com.wolf.pojo.Wl_seller;
import com.wolf.service.Wl_sellerService;
import org.apache.tomcat.util.http.fileupload.util.Streams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
@ComponentScan
public class Wl_sellerController {
    @Autowired
    Wl_sellerService wl_sellerService;

    /**
     * 查询所有
     */
    @RequestMapping("wl_seller_getAll")
    public String getAll(ModelMap m){
        List<Wl_seller> list=wl_sellerService.getall();
        if(list.size()!=0 || list.isEmpty())
            m.addAttribute("list", list);
            return "wl_seller";
        }


    /**
     * 新增
     */
    @RequestMapping("wl_seller_save")
    public String save(Wl_seller wl_seller){
        Date date=new Date();
        wl_seller.setCreatetime(date);

        int insert=wl_sellerService.insert(wl_seller);
        if (insert>0){
                return "redirect:wl_seller_getAll";
        }else {
            return "wl_seller_insert";
        }
    }


    /**
     * 删除
     */
    @RequestMapping("wl_seller_remove")
    public String remove(String id,Wl_seller wl_seller){
        int bb=wl_sellerService.updateStatus(id,"0");
        if (bb>0){
            return "redirect:wl_seller_getAll";
        }else {
            return "redirect:wl_seller_getAll";
        }
    }

    /**
     * 根据id查询
     */
    @RequestMapping("wl_seller_findbyid")
    public String findbyid(ModelMap m,String id){
        Wl_seller wl=wl_sellerService.selectByPrimaryKey(id);
        m.addAttribute("wl", wl);
        return "wl_seller_update";
    }

    /**
     * 修改
     */
    @RequestMapping("wl_seller_update")
    public String update(Wl_seller ww){
        int sc=wl_sellerService.updateByPrimaryKey(ww);
        if (sc>0){
            return "redirect:wl_seller_getAll";
        }else {
            return "redirect:wl_seller_findbyid";
        }
    }

    /**
     * 模糊查询
     * @return
     */
    @RequestMapping("wl_seller_fuzzQuery")
    public String fuzzQuery(ModelMap m,String stac,String sname){
        List<Wl_seller> fuzzlist=wl_sellerService.fuzzQuery(stac,sname);
        m.addAttribute("list",fuzzlist);
        return "wl_seller";
    }
    }
